﻿#region using
using AwesomeTanks.Sources.ScreenManagement;
using Microsoft.Xna.Framework;
using AwesomeTanks.Sources.Media;
#endregion


namespace AwesomeTanks.Sources.Screens
{
    /// <summary>
    /// Screen with the title of the game.
    /// </summary>
    public class TitleScreen : GameScreen
    {
        #region Fields
        private const int TITLE_SCREEN_DURATION = 3000; //ms
        private const int SOUND_START = 2500;

        private int currentTime = TitleScreen.TITLE_SCREEN_DURATION;
        private bool soundPlayed = false;
        #endregion

        #region Update and Draw

        /// <summary>
        /// Update the timer of the title screen.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="otherScreenHasFocus">if set to <c>true</c> [other screen has focus].</param>
        /// <param name="coveredByOtherScreen">if set to <c>true</c> [covered by other screen].</param>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            currentTime -= gameTime.ElapsedGameTime.Milliseconds;

            if (currentTime < SOUND_START && !soundPlayed)
            {
                soundPlayed = true;
                Sound.Pineapple.Play(1f, 0f, 0f);
            }

            if (currentTime < 0)
            {
                LoadingScreen.Load(ScreenManager, false, null, new BackgroundScreen(Art.MENU_BACKGROUND_PATH),
                                                           new MainMenuScreen());
            }

            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
        }
        #endregion
    }
}
